<% layout('/layouts/default.html', {title: '提单管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-body">
			<#form:form id="searchForm" model="${ladingBill}" action="${ctx}/logistics/ladingbill/ladingBill/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('单据编号')}：</label>
					<div class="control-inline">
						<#form:input path="ladingBillCode" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('提单号')}：</label>
					<div class="control-inline">
						<#form:input path="ladingBillNumber" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('提单日期')}：</label>
					<div class="control-inline">
						<#form:input path="date_gte" readonly="true" maxlength="20" class="form-control laydate width-date"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="date_lte.click()"/>
						&nbsp;-&nbsp;
						<#form:input path="date_lte" readonly="true" maxlength="20" class="form-control laydate width-date"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('银行到单日期')}：</label>
					<div class="control-inline">
						<#form:input path="bankArrivalDate_gte" readonly="true" maxlength="20" class="form-control laydate width-date"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="bankArrivalDate_lte.click()"/>
						&nbsp;-&nbsp;
						<#form:input path="bankArrivalDate_lte" readonly="true" maxlength="20" class="form-control laydate width-date"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('保单号')}：</label>
					<div class="control-inline">
						<#form:input path="policyNumber" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('服务订单')}：</label>
					<div class="control-inline width-120">
						<#form:select path="serviceOrderId" dictType="" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('客户名称')}：</label>
					<div class="control-inline width-120">
						<#form:select path="customerId" dictType="" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('运输方式')}：</label>
					<div class="control-inline width-120">
						<#form:select path="transportMethod" dictType="erp_transport_type" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('预计起航时间')}：</label>
					<div class="control-inline">
						<#form:input path="estimatedFromDate_gte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm" data-done="estimatedFromDate_lte.click()"/>
						&nbsp;-&nbsp;
						<#form:input path="estimatedFromDate_lte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('预计到港时间')}：</label>
					<div class="control-inline">
						<#form:input path="estimatedToDate_gte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm" data-done="estimatedToDate_lte.click()"/>
						&nbsp;-&nbsp;
						<#form:input path="estimatedToDate_lte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('实际起航时间')}：</label>
					<div class="control-inline">
						<#form:input path="actualFromDate_gte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm" data-done="actualFromDate_lte.click()"/>
						&nbsp;-&nbsp;
						<#form:input path="actualFromDate_lte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('实际到港时间')}：</label>
					<div class="control-inline">
						<#form:input path="actualToDate_gte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm" data-done="actualToDate_lte.click()"/>
						&nbsp;-&nbsp;
						<#form:input path="actualToDate_lte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('创建者')}：</label>
					<div class="control-inline">
						<#form:input path="createBy" maxlength="64" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('创建时间')}：</label>
					<div class="control-inline">
						<#form:input path="createDate_gte" readonly="true" maxlength="20" class="form-control laydate width-date"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="createDate_lte.click()"/>
						&nbsp;-&nbsp;
						<#form:input path="createDate_lte" readonly="true" maxlength="20" class="form-control laydate width-date"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<div class="row">
				<div class="col-xs-10 pr10">
					<table id="dataGrid"></table>
					<div id="dataGridPage"></div>
				</div>
				<div class="col-xs-2 pl0">
					<div id="selectData" class="tags-input"></div>
				</div>
			</div>
		</div>
	</div>
</div>
<% } %>
<script>
var selectData = ${isNotBlank(selectData!) ? selectData! : "{\}"},
selectNum = 0, dataGrid = $('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("提单ID")}', name:'ladingBillId', index:'a.lading_bill_id', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return (val||row.id);
		}},
		{header:'${text("单据编号")}', name:'ladingBillCode', index:'a.lading_bill_code', width:150, align:"left"},
		{header:'${text("到单提醒")}', name:'arrivalReminderCode', index:'a.arrival_reminder_code', width:150, align:"left"},
		{header:'${text("提单号")}', name:'ladingBillNumber', index:'a.lading_bill_number', width:150, align:"left"},
		{header:'${text("提单日期")}', name:'date', index:'a.date', width:150, align:"center"},
		{header:'${text("银行到单日期")}', name:'bankArrivalDate', index:'a.bank_arrival_date', width:150, align:"center"},
		{header:'${text("保单号")}', name:'policyNumber', index:'a.policy_number', width:150, align:"left"},
		{header:'${text("服务订单")}', name:'serviceOrderId', index:'a.service_order_id', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('')}, val, '${text("未知")}', true);
		}},
		{header:'${text("国内资方")}', name:'investorId', index:'a.investor_id', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('')}, val, '${text("未知")}', true);
		}},
		{header:'${text("客户名称")}', name:'customerId', index:'a.customer_id', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('')}, val, '${text("未知")}', true);
		}},
		{header:'${text("供货外商")}', name:'supplierId', index:'a.supplier_id', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('')}, val, '${text("未知")}', true);
		}},
		{header:'${text("外商名称")}', name:'foreignBusinessmenId', index:'a.foreign_businessmen_id', width:150, align:"left"},
		{header:'${text("付款方式")}', name:'paymentMethod', index:'a.payment_method', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('payment_method')}, val, '${text("未知")}', true);
		}},
		{header:'${text("备注信息")}', name:'remarks', index:'a.remarks', width:150, align:"left"},
		{header:'${text("运输公司")}', name:'transportCompany', index:'a.transport_company', width:150, align:"left"},
		{header:'${text("运输方式")}', name:'transportMethod', index:'a.transport_method', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('erp_transport_type')}, val, '${text("未知")}', true);
		}},
		{header:'${text("起运港")}', name:'fromPort', index:'a.from_port', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('erp_harbor_list')}, val, '${text("未知")}', true);
		}},
		{header:'${text("目的港")}', name:'toPort', index:'a.to_port', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('erp_harbor_list')}, val, '${text("未知")}', true);
		}},
		{header:'${text("预计起航时间")}', name:'estimatedFromDate', index:'a.estimated_from_date', width:150, align:"center"},
		{header:'${text("预计到港时间")}', name:'estimatedToDate', index:'a.estimated_to_date', width:150, align:"center"},
		{header:'${text("实际起航时间")}', name:'actualFromDate', index:'a.actual_from_date', width:150, align:"center"},
		{header:'${text("实际到港时间")}', name:'actualToDate', index:'a.actual_to_date', width:150, align:"center"},
		{header:'${text("箱型")}', name:'boxModel', index:'a.box_model', width:150, align:"left"},
		{header:'${text("箱量")}', name:'boxQty', index:'a.box_qty', width:150, align:"left"},
		{header:'${text("箱号")}', name:'boxNumber', index:'a.box_number', width:150, align:"left"},
		{header:'${text("数量")}', name:'qty', index:'a.qty', width:150, align:"center"},
		{header:'${text("创建者")}', name:'createBy', index:'a.create_by', width:150, align:"left"},
		{header:'${text("创建时间")}', name:'createDate', index:'a.create_date', width:150, align:"center"},
		{header:'${text("更新者")}', name:'updateBy', index:'a.update_by', width:150, align:"left"},
		{header:'${text("更新时间")}', name:'updateDate', index:'a.update_date', width:150, align:"center"},
		{header:'行数据', name:'rowData', hidden:true, formatter: function(val, obj, row, act){
			return JSON.stringify(row);
		}}
	],
	autoGridHeight: function(){
		var height = $(window).height() - $('#searchForm').height() - $('#dataGridPage').height() - 74;
		$('.tags-input').height($('.ui-jqgrid').height() - 10);
		return height;
	},
	showCheckbox: '${parameter.checkbox}' == 'true',
	multiboxonly: false, // 单击复选框时再多选
	ajaxSuccess: function(data){
		$.each(selectData, function(key, value){
			dataGrid.dataGrid('setSelectRow', key);
		});
		initSelectTag();
	},
	onSelectRow: function(id, isSelect, event){
		if ('${parameter.checkbox}' == 'true'){
			if(isSelect){
				selectData[id] = JSON.parse(dataGrid.dataGrid('getRowData', id).rowData);
			}else{
				delete selectData[id];
			}
		}else{
			selectData = {};
			selectData[id] = JSON.parse(dataGrid.dataGrid('getRowData', id).rowData);
		}
		initSelectTag();
	},
	onSelectAll: function(ids, isSelect){
		if ('${parameter.checkbox}' == 'true'){
			for (var i=0; i<ids.length; i++){
				if(isSelect){
					selectData[ids[i]] = JSON.parse(dataGrid.dataGrid('getRowData', ids[i]).rowData);
				}else{
					delete selectData[ids[i]];
				}
			}
		}
		initSelectTag();
	},
	ondblClickRow: function(id, rownum, colnum, event){
		if ('${parameter.checkbox}' != 'true'){
			js.layer.$('#' + window.name).closest('.layui-layer')
				.find(".layui-layer-btn0").trigger("click");
		}
		initSelectTag();
	}
});
function initSelectTag(){
	selectNum = 0;
	var html = [];
	$.each(selectData, function(key, value){
		selectNum ++;
		html.push('<span class="tag" id="'+key+'_tags-input"><span>'+(value.ladingBillId||value.id)+' </span>'
			+ '<a href="#" onclick="removeSelectTag(\''+key+'\');" title="${text("取消选择")}">x</a></span>');
	});
	html.unshift('<div class="title">${text("当前已选择 {0\} 项", "<span id=\"selectNum\">'+selectNum+'</span>")}：</div>');
	$('#selectData').empty().append(html.join(''));
}
function removeSelectTag(key){
	delete selectData[key];
	dataGrid.dataGrid('resetSelection', key);
	$('#selectNum').html(--selectNum);
	$('#'+key+'_tags-input').remove();
}
function getSelectData(){
	return selectData;
}
</script>